package cn.zwxky.android.staff.Approve;

import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.daasuu.bl.BubbleLayout;
import com.facebook.drawee.view.SimpleDraweeView;
import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.config.Config;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.SN;

import java.util.HashMap;

import cn.zwxky.android.staff.R;
import cn.zwxky.android.staff.Utils.LittleUtils;
import cn.zwxky.android.staff.Utils.URLString;



/**
 * 请假详情
 * Created by Administrator on 2017/3/29 0029.
 */
@ContentView(R.layout.aty_leave_details)
public class LeaveDetailsActivity extends LsfbActivity {


    @ViewInject(R.id.aty_leave_staff_yingcang_line)
    private LinearLayout yingcang_line;

    @ViewInject(R.id.yingcang_qipao)
    private BubbleLayout yingcang_qipao;


    /**
     * 头像
     */
    @ViewInject(R.id.aty_leave_img_head)
    private SimpleDraweeView img_head;

    /**
     * 请假人
     */
    @ViewInject(R.id.aty_leave_details_text_name)
    private TextView text_name;

    /**
     * 开始时间
     */
    @ViewInject(R.id.aty_leave_details_text_start_time)
    private TextView start_time;

    /**
     * 结束时间
     */
    @ViewInject(R.id.aty_leave_details_text_end_time)
    private TextView end_time;
    /**
     * 请假缘由
     */
    @ViewInject(R.id.aty_leave_details_text_why)
    private TextView text_why;

    /**
     * 员工状态
     */
    @ViewInject(R.id.aty_leave_staff_img_status)
    private ImageView staff_img_status;

    /**
     * 部长状态
     */
    @ViewInject(R.id.aty_leave_minister_img_status)
    private ImageView minister_img_status;

    /**
     * 总经理状态
     */
    @ViewInject(R.id.aty_leave_manager_img_status)
    private ImageView manager_img_status;

    /**
     * 员工头像
     */
    @ViewInject(R.id.item_leave_img_head1)
    private SimpleDraweeView img_head1;

    /**
     * 员工名字
     */
    @ViewInject(R.id.aty_leave_staff_text_name)
    private TextView staff_text_name;

    /**
     * 员工内容
     */
    @ViewInject(R.id.aty_leave_staff_text_content)
    private TextView staff_text_content;

    /**
     * 员工时间
     */
    @ViewInject(R.id.aty_leave_staff_text_time)
    private TextView staff_text_time;

    /**
     * 部长头像
     */
    @ViewInject(R.id.item_leave_img_head2)
    private SimpleDraweeView img_head2;

    /**
     * 部长名字
     */
    @ViewInject(R.id.aty_leave_minister_text_name)
    private TextView minister_text_name;

    /**
     * 部长内容
     */
    @ViewInject(R.id.aty_leave_minister_text_content)
    private TextView minister_text_content;

    /**
     * 部长时间
     */
    @ViewInject(R.id.aty_leave_minister_text_time)
    private TextView minister_text_time;

    /**
     * 总经理头像
     */
    @ViewInject(R.id.item_leave_img_head3)
    private SimpleDraweeView img_head3;

    /**
     * 总经理名字
     */
    @ViewInject(R.id.aty_leave_manager_text_name)
    private TextView manager_text_name;

    /**
     * 总经理内容
     */
    @ViewInject(R.id.aty_leave_manager_text_content)
    private TextView manager_text_content;

    /**
     * 总经理时间
     */
    @ViewInject(R.id.aty_leave_manager_text_time)
    private TextView manager_text_time;

    private String id = "";

    @Override
    public void initView() {
        LittleUtils.setsimpletitlebar(this, "请假审批");
        id = getIntent().getStringExtra("id");


    }

    @Override
    public void initEvent() {

    }

    @Override
    public void initData() {
        getData();
    }

    public void getData() {
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("uid", Config.getUserId());
        hashMap.put("id", id);
        new BaseInternet().getData_Get(URLString.LEAVE_CON, hashMap, LeaveDetailsBean.class, new LeaveDetailsEvent<LeaveDetailsBean>(), true);
    }

    @EventAnnotation
    public void LeaveDetailsEvent(LeaveDetailsEvent<LeaveDetailsBean> event) {
        switch (event.getCode()) {
            case 200:
                text_name.setText(event.getData().getName());
                img_head.setImageURI(Uri.parse(URLString.IMG_URL + event.getData().getImg()));
                start_time.setText("开始时间："+event.getData().getStart());
                end_time.setText("结束时间："+event.getData().getEnd());
                text_why.setText("请假事由："+event.getData().getContent());
                if (event.getData().getList().size()==2){
                    staff_img_status.setImageResource(R.mipmap.img_zhong);
                    yingcang_line.setVisibility(View.GONE);
                    yingcang_qipao.setVisibility(View.GONE);
                    staff_img_status.setVisibility(View.GONE);
                    staff_text_name.setText("");
                    staff_text_content.setText("");
                    staff_text_time.setText("");

                    //0审批中，1通过，2拒绝
                    if (event.getData().getList().get(0).getStatus().equals("0")){
                        minister_img_status.setImageResource(R.mipmap.img_zhong);
                        minister_text_content.setTextColor(getResources().getColor(R.color.bottom_unchecked_color));
                    }else  if (event.getData().getList().get(0).getStatus().equals("1")){
                        minister_img_status.setImageResource(R.mipmap.img_yes);
                        minister_text_content.setTextColor(getResources().getColor(R.color.label_green));
                    }else  if (event.getData().getList().get(0).getStatus().equals("2")){
                        minister_img_status.setImageResource(R.mipmap.img_no);
                        minister_text_content.setTextColor(getResources().getColor(R.color.label_red));
                    }
                    img_head2.setImageURI(Uri.parse(URLString.IMG_URL + event.getData().getList().get(0).getImg()));
                    minister_text_name.setText(event.getData().getList().get(0).getName());
                    minister_text_content.setText(event.getData().getList().get(0).getMsg());
                    minister_text_time.setText(event.getData().getList().get(0).getTimes());

                    //0审批中，1通过，2拒绝
                    if (event.getData().getList().get(1).getStatus().equals("0")){
                        manager_img_status.setImageResource(R.mipmap.img_zhong);
                        manager_text_content.setTextColor(getResources().getColor(R.color.bottom_unchecked_color));
                    }else  if (event.getData().getList().get(1).getStatus().equals("1")){
                        manager_img_status.setImageResource(R.mipmap.img_yes);
                        manager_text_content.setTextColor(getResources().getColor(R.color.label_green));
                    }else  if (event.getData().getList().get(1).getStatus().equals("2")){
                        manager_img_status.setImageResource(R.mipmap.img_no);
                        manager_text_content.setTextColor(getResources().getColor(R.color.label_red));
                    }
                    img_head3.setImageURI(Uri.parse(URLString.IMG_URL + event.getData().getList().get(1).getImg()));
                    manager_text_name.setText(event.getData().getList().get(1).getName());
                    manager_text_content.setText(event.getData().getList().get(1).getMsg());
                    manager_text_time.setText(event.getData().getList().get(1).getTimes());

                }else if (event.getData().getList().size()==3){
                    //0审批中，1通过，2拒绝
                    yingcang_line.setVisibility(View.VISIBLE);
                    yingcang_qipao.setVisibility(View.VISIBLE);
                    staff_img_status.setVisibility(View.VISIBLE);
                    if (event.getData().getList().get(0).getStatus().equals("0")){
                        staff_img_status.setImageResource(R.mipmap.img_zhong);
                        staff_text_content.setTextColor(getResources().getColor(R.color.bottom_unchecked_color));
                    }else  if (event.getData().getList().get(0).getStatus().equals("1")){
                        staff_img_status.setImageResource(R.mipmap.img_yes);
                        staff_text_content.setTextColor(getResources().getColor(R.color.label_green));
                    }else  if (event.getData().getList().get(0).getStatus().equals("2")){
                        staff_img_status.setImageResource(R.mipmap.img_no);
                        staff_text_content.setTextColor(getResources().getColor(R.color.label_red));
                    }
                    img_head1.setImageURI(Uri.parse(URLString.IMG_URL + event.getData().getList().get(0).getImg()));
                    staff_text_name.setText(event.getData().getList().get(0).getName());
                    staff_text_content.setText(event.getData().getList().get(0).getMsg());
                    staff_text_time.setText(event.getData().getList().get(0).getTimes());

                    //0审批中，1通过，2拒绝
                    if (event.getData().getList().get(1).getStatus().equals("0")){
                        minister_img_status.setImageResource(R.mipmap.img_zhong);
                        minister_text_content.setTextColor(getResources().getColor(R.color.bottom_unchecked_color));
                    }else  if (event.getData().getList().get(1).getStatus().equals("1")){
                        minister_img_status.setImageResource(R.mipmap.img_yes);
                        minister_text_content.setTextColor(getResources().getColor(R.color.label_green));
                    }else  if (event.getData().getList().get(1).getStatus().equals("2")){
                        minister_img_status.setImageResource(R.mipmap.img_no);
                        minister_text_content.setTextColor(getResources().getColor(R.color.label_red));
                    }
                    img_head2.setImageURI(Uri.parse(URLString.IMG_URL + event.getData().getList().get(1).getImg()));
                    minister_text_name.setText(event.getData().getList().get(1).getName());
                    minister_text_content.setText(event.getData().getList().get(1).getMsg());
                    minister_text_time.setText(event.getData().getList().get(1).getTimes());

                    //0审批中，1通过，2拒绝
                    if (event.getData().getList().get(2).getStatus().equals("0")){
                        manager_img_status.setImageResource(R.mipmap.img_zhong);
                        manager_text_content.setTextColor(getResources().getColor(R.color.bottom_unchecked_color));
                    }else  if (event.getData().getList().get(2).getStatus().equals("1")){
                        manager_img_status.setImageResource(R.mipmap.img_yes);
                        manager_text_content.setTextColor(getResources().getColor(R.color.label_green));
                    }else  if (event.getData().getList().get(2).getStatus().equals("2")){
                        manager_img_status.setImageResource(R.mipmap.img_no);
                        manager_text_content.setTextColor(getResources().getColor(R.color.label_red));
                    }
                    img_head3.setImageURI(Uri.parse(URLString.IMG_URL + event.getData().getList().get(2).getImg()));
                    manager_text_name.setText(event.getData().getList().get(2).getName());
                    manager_text_content.setText(event.getData().getList().get(2).getMsg());
                    manager_text_time.setText(event.getData().getList().get(2).getTimes());
                }

                break;
            default:
                SN.SnackShow(img_head,event.getMsg());
                break;
        }
    }


}
